package iterator

type Iterator interface {
	Next() *Student
	HasNext() bool
}

type Iterable interface {
	Iterator() Iterator
}

type Student struct {
	Name   string
	Age    int
	Gender string
}

type Class struct {
	name     string
	students []*Student
}

func NewClass(name string) *Class {
	return &Class{name: name}
}

func (c *Class) AddStudent(students ...*Student) {
	c.students = append(c.students, students...)
}

func (c *Class) Iterator() Iterator {
	return &ClassIterator{
		class: c,
		index: 0,
	}
}

type ClassIterator struct {
	class *Class
	index int
}

func (c *ClassIterator) Next() *Student {
	if c.HasNext() {
		stu := c.class.students[c.index]
		c.index++
		return stu
	}
	return nil
}

func (c *ClassIterator) HasNext() bool {
	return c.index < len(c.class.students)
}
